/**
 * 
 */
package com.estock.common.model.task.enums;

/**
 * @author richard
 *
 */
public enum TaskFrequency {
	ONCE(1, "Once"), DAILY(2, "Daily"), WEEKLY(3, "Weekly"), CUSTOM(4, "Custom");
	
	private int frequency;
	private String desc;
	
	TaskFrequency(int frequency, String desc) {
		this.frequency = frequency;
		this.desc = desc;
	}
	
	public int getFrequency() {
		return this.frequency;
	}
	
	public String getDesc() {
		return desc;
	}

	public static String getDescByFrequency(int frequency) {
		if (TaskFrequency.ONCE.frequency == frequency) {
			return TaskFrequency.ONCE.desc;
		} else if (TaskFrequency.DAILY.frequency == frequency) {
			return TaskFrequency.DAILY.desc;
		} else if (TaskFrequency.WEEKLY.frequency == frequency) {
			return TaskFrequency.WEEKLY.desc;
		} else if (TaskFrequency.CUSTOM.frequency == frequency) {
			return TaskFrequency.CUSTOM.desc;
		}
		throw new RuntimeException("Unsupported task frequency.");
	}
	
	public static boolean isRepeated(int frequency) {
		return !(frequency == TaskFrequency.ONCE.frequency);
	}
	
}
